<template>
	<div>
		<input placeholder="用户名" v-model="form.username"/><br/><br/>
		<input placeholder="密码" v-model="form.password" type="password"/><br/><br/>
		<button @click="loginFun">登录</button>
		
	</div>
</template>
<script>
	//引入axios框架
	import Cookies from 'js-cookie'
	import {userLogin} from '@/api/user.js'
	
	export default{
		data(){
			return{
				form:{
					username:"admin",
					password:"macro123"
				}
			}
		},
		methods:{
			loginFun(){
				//发送请求给后台
				console.log(this.form)
				// axios.post("http://admin-api.macrozheng.com/admin/login",this.form)
				// axios.post("http://8.129.190.90:8081/admin/login",this.form)
				
				userLogin(this.form)
				.then(resp=>{
					console.log("resp",resp);
					let data = resp;
					if(data.code == 200){
						//成功
						//提取令牌
						let token = data.data.tokenHead + data.data.token;
						//将令牌保存起来    cookie 
						// 浏览器的缓存(放东西的)
						Cookies.set("token",token)
						
						this.$router.push("/home");
					}else{
						//失败
						 this.$message.error(resp.data.message);
					}
					
				})
			}
		}
	}
</script>
<style></style>